﻿using System.Linq;
using NUnit.Framework;
using StreetPacMan.Server.Facade;

namespace StreetPacMan.Server.Tests.Integ
{
    [TestFixture]
    public class PacManJoined : BddBase
    {
        private readonly GetGameStateResult GameInstance;
        private readonly IServerFacade ServerFacade;

        public PacManJoined()
        {
            ServerFacade = ServerFacadeFactory.GetServerFacade();
            ServerFacade.CreateGameX("GameName");
            var pacman = ServerFacade.JoinGameX("GameName", "PacManName", PlayerRole.PacMan);
            GameInstance = ServerFacade.GetGameStateForX(pacman.PlayerId);
        }

        [Test]
        public void PacManProeprtiesShouldBeCorrect()
        {
            var pacman = GameInstance.Players.Last();
            Assert.AreEqual("PacManName", pacman.Name);
            Assert.AreEqual(PlayerRole.PacMan, pacman.Role);
        }

        [Test]
        public void GameStateShouldBeWaitingForMorePlayersToJoin()
        {
            Assert.AreEqual(GameState.WaitingForMorePlayersToJoin, GameInstance.State);
        }

        [Test]
        public void MessageShouldBePacManJoined()
        {
            Assert.AreEqual("PacManName joined as PacMan", GameInstance.LastGameMessage);
        }

        [Test]
        public void OneEventOfPlayerJoinedShouldExists()
        {
            var allEvents = ServerFacade.GetAllEventsX("GameName");
            Assert.AreEqual(1, allEvents.Events.Where(x=>x.Type==EventType.PlayerJoined).Count());
        }
    }
}